package cn.itcast.execption;


import cn.itcast.entity.ErrorResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class ExceptionaAdvice {

    //处理系统业务异常
    @ExceptionHandler(BusinessException.class)
    public ResponseEntity handlerBusinessException(BusinessException exception) {
        exception.printStackTrace();
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(exception.getErrorResult());
    }

    //处理系统不可知异常
    @ExceptionHandler(Exception.class)
    public ResponseEntity handlerException(Exception exception) {
        exception.printStackTrace();
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ErrorResult.error());
    }
}
